package com.imooc.miaosha.controller;

import com.imooc.miaosha.pojo.ApiResultTo;
import com.imooc.miaosha.pojo.CodeMsg;
import com.imooc.miaosha.pojo.domain.MiaoshaUser;
import com.imooc.miaosha.pojo.vo.LoginVo;
import com.imooc.miaosha.service.MiaoshaUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
public class LoginController {
    final Logger logger= LoggerFactory.getLogger(LoginController.class);
    @Autowired
    MiaoshaUserService miaoshaUserService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ApiResultTo<?> login(@RequestBody @Valid LoginVo user, HttpServletResponse response){
        MiaoshaUser miaoshaUser = miaoshaUserService.login(response, user.getPassword(), user.getMobile());
        return ApiResultTo.buildSuccess(miaoshaUser);
    }
    @RequestMapping(value = "/user_info", method = RequestMethod.POST)
    public ApiResultTo<MiaoshaUser> userInfo(MiaoshaUser user){
        return ApiResultTo.buildSuccess(user);
    }
}
